<?php
/**
 * Created by PhpStorm.
 * User: LI
 * Date: 2015/11/25
 * Time: 14:35
 */
namespace Reviews\Controller;
use Think\Controller;
use Reviews\Model;
header("content-type:text/html;charset=utf-8");
class StoreController extends Controller{
	public function index(){
       // $model_admin = D('store');//直接访问数据库
       // $model_admin -> select();
       // $this -> display('index');//直接访问view目录下store_list目录下的文件名为"参数.php"的模版
    // }
    // public function home(){
    //     $this -> display('index');
    // }
    // //show_store_list
    // public function show_store_list(){
    //     // $this -> display('index');
        $model_store = D('store');
    //     // <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        // dump($model_store->select());
        $store_list = $model_store->select();
        $this->assign('store_list', $store_list);
        // $this->assign('LA', $LA="LALALALALA");
        $this->display('index');

    }
    public function show_detial(){
        // echo "LALALALA<br/>";
        // echo $_GET['sid'];
        $sid=$_GET['sid'];
        $model_store = D('store');
        $model_review = D('review');
        // $this->getReviews($sid);
        // $store_list = 
        $sql['Sid']=$sid;
        // dump ($model_store->where($sql)->select());
        $store_info=$model_store->where($sql)->select();
        $store_reviews_info=$model_review->where($sql)->select();
        
        $rsum=0;
        $rnum=0;
        foreach ($store_reviews_info as $key => $value) {
            # code...
            $rsum+=$value['score'];
            $rnum++;
        }
        $avg=$rsum/$rnum;


        $this->assign('avg_score', $avg);
        $this->assign('store_reviews_info', $store_reviews_info);
        $this->assign('store_info', $store_info);
        $this->display('single');

        // dump ($store_info);
        // dump ($store_reviews_info);

        // $sql['Sid']=$sid;
        // return $store_reviews_info;
    }
    public function add_review(){
        $sid=$_POST['sid'];
        // $model_review = D('review');
        // $sql['Sid']=$sid;
        // $store_reviews_info=$model_review->where($sql)->select();
        // return $store_reviews_info;
        dump ($sid);
    }
    // public function getReviews($sid){
    //     $model_review = D('review');
    //     $sql['Sid']=$sid;
    //     $store_reviews_info=$model_review->where($sql)->select();
    //     return $store_reviews_info;
    // }
    //     // $store_list = $model_store->getStoreList();
    //     // print_r("$store_list") ;
    // }
    // public function add_store(){
    //     $this -> display('add_store');
    //     // $model_store = D('store');
    //     // <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    //     // dump($model_store->select());
    //     // $store_list = $model_store->getStoreList();
    //     // print_r("$store_list") ;
    // }
    // public function save_store(){
    //     $this -> display('index');
    //     // $model_store = D('store');
    //     // <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    //     // dump($model_store->select());
    //     // $store_list = $model_store->getStoreList();
    //     // print_r("$store_list") ;
    // }
}